
#include <BLayout>
#include <BShortcut>
#include "StyleSheetDialog.h"

StyleSheetDialog::StyleSheetDialog(BWidget* parent) : BDialog(parent)
{
	this->setTitle("Style Sheet");

	_textEdit = new BTextEdit();
	BLayout* layout = new BLayout(this);
	layout->setWidget(_textEdit);

	BShortcut* saveShortcut = new BShortcut("ctrl+s", this);

	connect(_textEdit, Signal_TextEdited, &StyleSheetDialog::slotSheetTextEdited);
	connect(saveShortcut, Signal_Triggered, &StyleSheetDialog::slotSaveShortcutTriggered);
}
StyleSheetDialog::~StyleSheetDialog()
{

}

void StyleSheetDialog::setSheet(const BString& sheet)
{
	_textEdit->setText(sheet);
}
const BString& StyleSheetDialog::sheet() const
{
	return _textEdit->text();
}

void StyleSheetDialog::slotSheetTextEdited()
{
	BString title = this->title();
	if (!title.endWith('*'))
	{
		title += '*';
		this->setTitle(title);
	}
}
void StyleSheetDialog::slotSaveShortcutTriggered()
{
	BString title = this->title();
	if (title.endWith('*'))
	{
		title -= '*';
		this->setTitle(title);
		this->emit(Signal_Finished);
	}
}

